package com.laosg.resource.ssoclient2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableOAuth2Sso
@RestController
@SpringBootApplication
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SSOServer2ApplicationRun {
  
  private static final Logger log = LoggerFactory.getLogger(SSOServer2ApplicationRun.class);

  public static void main(String[] args) {
    SpringApplication.run(SSOServer2ApplicationRun.class, args);
  }
  
  @GetMapping("/user2")
  @PreAuthorize("hasAuthority('appInfo')")
  public Authentication getUser(Authentication authentication) {
    log.info("resource: user {}", authentication);
    return authentication;
  }

}
